package com.elitel.common.auth.config;


import com.elitel.common.auth.AuthProperties;
import com.elitel.common.auth.filter.Oauth2Filter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author hi_bj
 */
@Configuration
@ConditionalOnProperty(prefix = "auth", name = "type", havingValue = "oauth2")
public class Oauth2Config {

    @Resource
    private AuthProperties authProperties;

    @Bean
    public FilterRegistrationBean oauth2Filter() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        Oauth2Filter oauth2Filter = new Oauth2Filter();
        oauth2Filter.setAuthProperties(authProperties);
        filterRegistrationBean.setFilter(oauth2Filter);
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(3);
        return filterRegistrationBean;
    }
}
